package com.blog.mapper;

import com.blog.entity.auth.Account;
import com.blog.entity.user.AccountUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select * from users where username = #{text} or email = #{text}")
    Account findAccountByNameOrEmail(String text);

    @Select("select * from users where username = #{text} or email = #{text}")
    AccountUser findAccountUserByNameOrEmail(String text);

    @Select("select * from users where uid = #{uid}")
    AccountUser getAccountByUid(int uid);

    @Select("select * from users;")
    List<AccountUser> getAccountList();

    @Insert("insert into users(email, username, password, role) VALUES(#{email}, #{username}, #{password}, 'user')")
    int createAccount(String username, String password, String email);

    @Update("update users set password = #{password} where uid = #{uid}")
    int resetPasswordByUid(String password, int uid);

    @Update("update users set password = #{password} where email = #{email}")
    int resetPasswordByEmail(String password, String email);

    @Delete("delete from users where uid = #{uid}")
    int deleteAccountByUid(int uid);
}
